home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 June
/
EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso
/
earcd
/
cmdity
/
yk212src.lha
/
Yak_2.12_Src
/
icon.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-01-18
|
6KB
|
347 lines
/*
* Routines dealing with processing of Yak's icon
* (be they for tooltypes or AppIcon purposes).
*
*/
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/wb.h>
#include <proto/icon.h>
#include <exec/types.h>
#include <exec/ports.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <workbench/startup.h>
#include <workbench/workbench.h>
#include <string.h>
#include "icon.h"
#include "yak.h"
struct MsgPort *AppMsgPort=NULL;
ULONG appsigflag=0L;
static struct DiskObject *diskobj;
__regargs BOOL
GetYakIcon(STRPTR name)
{
if (name)
{
/* Get Disk Object */
diskobj = GetDiskObject(name);
}
return (BOOL)(diskobj ? TRUE : FALSE);
}
/* can cope with multiple calls */
void
FreeYakIcon()
{
if (diskobj)
{
FreeDiskObject(diskobj);
diskobj = NULL;
}
}
/* like ArgString() */
__regargs char *
TTString(char *name, char *def)
{
char *what;
if (diskobj)
if (what = FindToolType(diskobj->do_ToolTypes, name))
return what;
return def;
}
/* like ArgInt() */
__regargs LONG
TTInt(char *name, LONG def)
{
char *what;
if (diskobj)
if (what = FindToolType(diskobj->do_ToolTypes, name))
StrToLong(what, &def);
return def;
}
/* simple extension to ArgXXX routines */
__regargs BOOL
TTBool(char *name, BOOL def)
{
char *s;
s = TTString(name, def ? "YES" : "NO");
return (BOOL)(((strcmp(s, "YES") == 0) ||
(strcmp(s, "TRUE") == 0) ||
(strcmp(s, "ON") == 0)) ? TRUE : FALSE);
}
#ifndef PREFS
#define APPICONS_NUM 32
static struct
{
struct AppIcon *appicon;
struct Window *window;
} iconified[APPICONS_NUM];
static BOOL
CreateAppIconPort(void)
{
if (AppMsgPort = CreateMsgPort())
{
appsigflag = 1 << AppMsgPort->mp_SigBit;
RegisterSignal(appsigflag);
return TRUE;
}
else
return FALSE;
}
/* create our AppIcon */
BOOL
MakeYakAppIcon(void)
{
if (diskobj != NULL)
{
if (CreateAppIconPort() == TRUE)
{
diskobj->do_CurrentX = TTInt("ICONXPOS", NO_ICON_POSITION);
diskobj->do_CurrentY = TTInt("ICONYPOS", NO_ICON_POSITION);
if (iconified[0].appicon = AddAppIconA(0, 0, TTString("ICONNAME", "Yak!"),
AppMsgPort, 0, diskobj, 0))
{
return TRUE;
}
else DeleteMsgPort(AppMsgPort);
}
}
return FALSE;
}
extern STRPTR ProgramName;
static char *
ChooseProgramName(struct Window *Window)
{
char *name = NULL;
struct Task *WinTask;
STRPTR TaskName;
if (Window->Flags & WFLG_WBENCHWINDOW)
{
/* It's probably a drawer */
name = "envarc:sys/def_drawer";
}
else
{
if ((WinTask = Window->UserPort->mp_SigTask) &&
(TaskName = WinTask->tc_Node.ln_Name))
{
/* Should be done by using patterns */
if (stricmp(TaskName,"KCON") == 0)
{
name = "sys:system/shell";
}
else
{
/* By default take Yak icon */
name = ProgramName;
}
}
}
return(name);
}
static char *
ChooseAppIconTitle(struct Window *Window)
{
char *title = NULL;
if (Window->Title)
{
title = Window->Title;
}
else
{
struct Task *WinTask;
STRPTR TaskName;
if ((WinTask = Window->UserPort->mp_SigTask) &&
(TaskName = WinTask->tc_Node.ln_Name))
{
title = TaskName;
}
else
{
title = "Iconified window";
}
}
return(title);
}
/* create our AppIcon */
__regargs BOOL
MakeAppIconified (struct Window *Window)
{
int ID;
BOOL error = TRUE;
for (ID=1; ID < APPICONS_NUM; ID++)
{
if (iconified[ID].window == Window)
{
/* This window has already been iconified
* Don't do it twice !
*/
return(FALSE);
}
}
/* Find an unused appicon */
ID = 1;
while ((iconified[ID].appicon != NULL) &&
(ID < APPICONS_NUM))
{
ID++;
}
if (ID == APPICONS_NUM)
{
/* No more memory left for iconification */
return(FALSE);
}
GetYakIcon(ChooseProgramName(Window));
if (diskobj == NULL)
{
/* Maybe the choosen program name doesn't exist so try
* once again with Yak icon
*/
GetYakIcon(ProgramName);
}
if (diskobj != NULL)
{
if (AppMsgPort == NULL)
{
/* Probably there's no appicon already created */
CreateAppIconPort();
}
if (AppMsgPort != NULL)
{
if (iconified[ID].appicon = AddAppIconA(ID, 0,
ChooseAppIconTitle(Window),
AppMsgPort, 0L, diskobj, 0L))
{
iconified[ID].window = Window;
}
else
{
error = FALSE;
}
}
FreeYakIcon();
}
else
{
error = FALSE;
}
return(error);
}
extern void RevealWindow(struct Window *window);
extern BOOL ShowYakInterface(void);
/* bye bye icons... */
void
RemoveAllAppIcons()
{
int i;
struct Message *msg;
/* Remove Yak appicon if any */
if (iconified[0].appicon != NULL)
{
RemoveAppIcon(iconified[0].appicon);
iconified[0].appicon = NULL;
}
for (i=1; i<APPICONS_NUM; i++)
{
if (iconified[i].appicon != NULL)
{
RevealWindow(iconified[i].window);
RemoveAppIcon(iconified[i].appicon);
iconified[i].appicon = NULL;
iconified[i].window = NULL;
}
}
if (AppMsgPort != NULL)
{
/* Clear the port */
while (msg = GetMsg(AppMsgPort))
ReplyMsg(msg);
DeleteMsgPort(AppMsgPort);
}
}
/* Process AppIcons messages if any */
void
ProcessAppMsg(ULONG sigrcvd)
{
struct AppMessage *appmsg;
ULONG ID;
if (sigrcvd & appsigflag)
{
while (appmsg = (struct AppMessage *)GetMsg(AppMsgPort))
{
ID = appmsg->am_ID;
ReplyMsg((struct Message *)appmsg);
if (ID == 0)
{
/* It's a message from Yak AppIcon */
ShowYakInterface();
}
else
{
/* It's a message from an AppIcon attached to an iconified window
* So let's close our appicon and deiconify window
*/
RemoveAppIcon(iconified[ID].appicon);
RevealWindow(iconified[ID].window);
iconified[ID].appicon = NULL;
iconified[ID].window = NULL;
}
}
}
}
#endif